/*
 * Copyright 2018 JDCLOUD.COM
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http:#www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * JCLOUD IoT Hub API
 * API related to IoT Hub
 *
 * OpenAPI spec version: v2
 * Contact: 
 *
 * NOTE: This class is auto generated by the jdcloud code generator program.
 */


using JDCloudSDK.Core.Auth;
using JDCloudSDK.Core.Client;
using JDCloudSDK.Core.Http;
using JDCloudSDK.Iothub.Apis;
using JDCloudSDK.Iothub.Model;
using System;
using System.Collections.Generic;
using System.Text;
#if NET40||NET35
#else
using System.Threading.Tasks;
#endif

namespace JDCloudSDK.Iothub.Client
{
    /// <summary>
    ///  JCLOUD IoT Hub API
    ///  API related to IoT Hub
    ///  Iothub Api 客户端
    ///</summary>
    public class IothubClient : JdcloudClient
    {

        /// <summary>
        ///  默认私有构造函数
        /// </summary>
        private IothubClient()
        {

        }

        /// <summary>
        /// 默认构造函数
        /// </summary>
        /// <param name="credentialsProvider">认证信息</param>
        /// <param name="httpRequestConfig">http 客户端配置信息</param>
        /// <param name="environment">sdk 环境配置信息</param>
        public IothubClient(CredentialsProvider credentialsProvider, HttpRequestConfig httpRequestConfig,SDKEnvironment environment)
        {
            this.httpRequestConfig = httpRequestConfig;
            this.credentialsProvider = credentialsProvider;
            this.environment = environment;
        }

        /// <summary>
        /// 默认构造函数
        /// </summary>
        /// <param name="httpRequestConfig">http 客户端配置信息</param>
        /// <param name="credentialsProvider">认证信息</param>
        public IothubClient(CredentialsProvider credentialsProvider,HttpRequestConfig httpRequestConfig)
        {
            this.httpRequestConfig = httpRequestConfig;
            this.credentialsProvider = credentialsProvider;
        }

        /// <summary>
        /// 默认构造函数，
        /// 注意如果使用此方法 httpRequestConfig 使用的http 请求 schema 为Https
        /// </summary>
        /// <param name="credentialsProvider">认证信息</param>
        public IothubClient(CredentialsProvider credentialsProvider)
        {
            this.credentialsProvider = credentialsProvider;
        }

        /// <summary>
        ///  版本号 1.2.0
        ///</summary>
        public const string ClientVersion = "1.2.0";

        private const string apiVersion = "v2";
        private const string userAgentPrefix = "JdcloudSdkDotNet";
        private const string defaultEndpoint = "iothub.jdcloud-api.com";
        private const string serviceName = "iothub";
        private const string userAgent = userAgentPrefix + "/" + ClientVersion + " " + serviceName + "/" + apiVersion;


        private SDKEnvironment environment = new SDKEnvironment(defaultEndpoint);
        private CredentialsProvider credentialsProvider;
        private HttpRequestConfig httpRequestConfig;

        /// <summary>
        ///  获取证书信息
        ///</summary>
        public override CredentialsProvider CredentialsProvider   { get { return credentialsProvider; } }

        /// <summary>
        ///  获取http 客户端配置信息
        ///</summary>
        public override HttpRequestConfig HttpRequestConfig { get { return httpRequestConfig; } }

        /// <summary>
        ///  获取sdk环境配置信息
        ///</summary>
        public override SDKEnvironment SDKEnvironment { get { return environment; } }

        /// <summary>
        ///  获取用户自定义浏览器识别字符串
        ///</summary>
        public override string UserAgent { get { return userAgent; } }

        /// <summary>
        ///  获取服务名称
        ///</summary>
        public override string ServiceName { get { return serviceName; } }

        /// <summary>
        ///  获取版本号
        ///</summary>
        public override string Version { get { return apiVersion; } }



#if NET40||NET35
        /// <summary>
        ///  修改设备详情
        /// </summary>
        /// <param name="request">请求参数信息</param>
        /// <returns>请求结果信息</returns>
        public UpdateDeviceResponse UpdateDevice(UpdateDeviceRequest request) {
            return  new UpdateDeviceExecutor().Client(this).Execute<UpdateDeviceResponse, UpdateDeviceResult, UpdateDeviceRequest>(request);
        }
#else
        /// <summary>
        ///  修改设备详情
        /// </summary>
        /// <param name="request">请求参数信息</param>
        /// <returns>请求结果信息</returns>
        public async Task<UpdateDeviceResponse> UpdateDevice(UpdateDeviceRequest request) {
            return await new UpdateDeviceExecutor().Client(this).Execute<UpdateDeviceResponse, UpdateDeviceResult, UpdateDeviceRequest>(request).ConfigureAwait(false);
        }
#endif
#if NET40||NET35
        /// <summary>
        ///  删除产品
        /// </summary>
        /// <param name="request">请求参数信息</param>
        /// <returns>请求结果信息</returns>
        public DeleteProductResponse DeleteProduct(DeleteProductRequest request) {
            return  new DeleteProductExecutor().Client(this).Execute<DeleteProductResponse, DeleteProductResult, DeleteProductRequest>(request);
        }
#else
        /// <summary>
        ///  删除产品
        /// </summary>
        /// <param name="request">请求参数信息</param>
        /// <returns>请求结果信息</returns>
        public async Task<DeleteProductResponse> DeleteProduct(DeleteProductRequest request) {
            return await new DeleteProductExecutor().Client(this).Execute<DeleteProductResponse, DeleteProductResult, DeleteProductRequest>(request).ConfigureAwait(false);
        }
#endif
#if NET40||NET35
        /// <summary>
        ///  查看产品功能列表接口
        /// </summary>
        /// <param name="request">请求参数信息</param>
        /// <returns>请求结果信息</returns>
        public ListProductAbilitiesResponse ListProductAbilities(ListProductAbilitiesRequest request) {
            return  new ListProductAbilitiesExecutor().Client(this).Execute<ListProductAbilitiesResponse, ListProductAbilitiesResult, ListProductAbilitiesRequest>(request);
        }
#else
        /// <summary>
        ///  查看产品功能列表接口
        /// </summary>
        /// <param name="request">请求参数信息</param>
        /// <returns>请求结果信息</returns>
        public async Task<ListProductAbilitiesResponse> ListProductAbilities(ListProductAbilitiesRequest request) {
            return await new ListProductAbilitiesExecutor().Client(this).Execute<ListProductAbilitiesResponse, ListProductAbilitiesResult, ListProductAbilitiesRequest>(request).ConfigureAwait(false);
        }
#endif
#if NET40||NET35
        /// <summary>
        ///  删除设备
        /// </summary>
        /// <param name="request">请求参数信息</param>
        /// <returns>请求结果信息</returns>
        public RemoveDeviceByIdResponse RemoveDeviceById(RemoveDeviceByIdRequest request) {
            return  new RemoveDeviceByIdExecutor().Client(this).Execute<RemoveDeviceByIdResponse, RemoveDeviceByIdResult, RemoveDeviceByIdRequest>(request);
        }
#else
        /// <summary>
        ///  删除设备
        /// </summary>
        /// <param name="request">请求参数信息</param>
        /// <returns>请求结果信息</returns>
        public async Task<RemoveDeviceByIdResponse> RemoveDeviceById(RemoveDeviceByIdRequest request) {
            return await new RemoveDeviceByIdExecutor().Client(this).Execute<RemoveDeviceByIdResponse, RemoveDeviceByIdResult, RemoveDeviceByIdRequest>(request).ConfigureAwait(false);
        }
#endif
#if NET40||NET35
        /// <summary>
        ///  导出物模型
        /// </summary>
        /// <param name="request">请求参数信息</param>
        /// <returns>请求结果信息</returns>
        public ExportThingModelResponse ExportThingModel(ExportThingModelRequest request) {
            return  new ExportThingModelExecutor().Client(this).Execute<ExportThingModelResponse, ExportThingModelResult, ExportThingModelRequest>(request);
        }
#else
        /// <summary>
        ///  导出物模型
        /// </summary>
        /// <param name="request">请求参数信息</param>
        /// <returns>请求结果信息</returns>
        public async Task<ExportThingModelResponse> ExportThingModel(ExportThingModelRequest request) {
            return await new ExportThingModelExecutor().Client(this).Execute<ExportThingModelResponse, ExportThingModelResult, ExportThingModelRequest>(request).ConfigureAwait(false);
        }
#endif
#if NET40||NET35
        /// <summary>
        ///  设备服务调用
        /// </summary>
        /// <param name="request">请求参数信息</param>
        /// <returns>请求结果信息</returns>
        public InvokeThingServiceResponse InvokeThingService(InvokeThingServiceRequest request) {
            return  new InvokeThingServiceExecutor().Client(this).Execute<InvokeThingServiceResponse, InvokeThingServiceResult, InvokeThingServiceRequest>(request);
        }
#else
        /// <summary>
        ///  设备服务调用
        /// </summary>
        /// <param name="request">请求参数信息</param>
        /// <returns>请求结果信息</returns>
        public async Task<InvokeThingServiceResponse> InvokeThingService(InvokeThingServiceRequest request) {
            return await new InvokeThingServiceExecutor().Client(this).Execute<InvokeThingServiceResponse, InvokeThingServiceResult, InvokeThingServiceRequest>(request).ConfigureAwait(false);
        }
#endif
#if NET40||NET35
        /// <summary>
        ///  删除设备
        /// </summary>
        /// <param name="request">请求参数信息</param>
        /// <returns>请求结果信息</returns>
        public RemoveDeviceResponse RemoveDevice(RemoveDeviceRequest request) {
            return  new RemoveDeviceExecutor().Client(this).Execute<RemoveDeviceResponse, RemoveDeviceResult, RemoveDeviceRequest>(request);
        }
#else
        /// <summary>
        ///  删除设备
        /// </summary>
        /// <param name="request">请求参数信息</param>
        /// <returns>请求结果信息</returns>
        public async Task<RemoveDeviceResponse> RemoveDevice(RemoveDeviceRequest request) {
            return await new RemoveDeviceExecutor().Client(this).Execute<RemoveDeviceResponse, RemoveDeviceResult, RemoveDeviceRequest>(request).ConfigureAwait(false);
        }
#endif
#if NET40||NET35
        /// <summary>
        ///  更新设备影子的期望值
        /// </summary>
        /// <param name="request">请求参数信息</param>
        /// <returns>请求结果信息</returns>
        public UpdateThingShadowResponse UpdateThingShadow(UpdateThingShadowRequest request) {
            return  new UpdateThingShadowExecutor().Client(this).Execute<UpdateThingShadowResponse, UpdateThingShadowResult, UpdateThingShadowRequest>(request);
        }
#else
        /// <summary>
        ///  更新设备影子的期望值
        /// </summary>
        /// <param name="request">请求参数信息</param>
        /// <returns>请求结果信息</returns>
        public async Task<UpdateThingShadowResponse> UpdateThingShadow(UpdateThingShadowRequest request) {
            return await new UpdateThingShadowExecutor().Client(this).Execute<UpdateThingShadowResponse, UpdateThingShadowResult, UpdateThingShadowRequest>(request).ConfigureAwait(false);
        }
#endif
#if NET40||NET35
        /// <summary>
        ///  查看产品
        /// </summary>
        /// <param name="request">请求参数信息</param>
        /// <returns>请求结果信息</returns>
        public DescribeProductResponse DescribeProduct(DescribeProductRequest request) {
            return  new DescribeProductExecutor().Client(this).Execute<DescribeProductResponse, DescribeProductResult, DescribeProductRequest>(request);
        }
#else
        /// <summary>
        ///  查看产品
        /// </summary>
        /// <param name="request">请求参数信息</param>
        /// <returns>请求结果信息</returns>
        public async Task<DescribeProductResponse> DescribeProduct(DescribeProductRequest request) {
            return await new DescribeProductExecutor().Client(this).Execute<DescribeProductResponse, DescribeProductResult, DescribeProductRequest>(request).ConfigureAwait(false);
        }
#endif
#if NET40||NET35
        /// <summary>
        ///  导入物模型
        /// </summary>
        /// <param name="request">请求参数信息</param>
        /// <returns>请求结果信息</returns>
        public ImportThingModelResponse ImportThingModel(ImportThingModelRequest request) {
            return  new ImportThingModelExecutor().Client(this).Execute<ImportThingModelResponse, ImportThingModelResult, ImportThingModelRequest>(request);
        }
#else
        /// <summary>
        ///  导入物模型
        /// </summary>
        /// <param name="request">请求参数信息</param>
        /// <returns>请求结果信息</returns>
        public async Task<ImportThingModelResponse> ImportThingModel(ImportThingModelRequest request) {
            return await new ImportThingModelExecutor().Client(this).Execute<ImportThingModelResponse, ImportThingModelResult, ImportThingModelRequest>(request).ConfigureAwait(false);
        }
#endif
#if NET40||NET35
        /// <summary>
        ///  查看设备影子
        /// </summary>
        /// <param name="request">请求参数信息</param>
        /// <returns>请求结果信息</returns>
        public DescribeThingShadowResponse DescribeThingShadow(DescribeThingShadowRequest request) {
            return  new DescribeThingShadowExecutor().Client(this).Execute<DescribeThingShadowResponse, DescribeThingShadowResult, DescribeThingShadowRequest>(request);
        }
#else
        /// <summary>
        ///  查看设备影子
        /// </summary>
        /// <param name="request">请求参数信息</param>
        /// <returns>请求结果信息</returns>
        public async Task<DescribeThingShadowResponse> DescribeThingShadow(DescribeThingShadowRequest request) {
            return await new DescribeThingShadowExecutor().Client(this).Execute<DescribeThingShadowResponse, DescribeThingShadowResult, DescribeThingShadowRequest>(request).ConfigureAwait(false);
        }
#endif
#if NET40||NET35
        /// <summary>
        ///  注册单个设备并返回秘钥信息
        /// </summary>
        /// <param name="request">请求参数信息</param>
        /// <returns>请求结果信息</returns>
        public AddDeviceResponse AddDevice(AddDeviceRequest request) {
            return  new AddDeviceExecutor().Client(this).Execute<AddDeviceResponse, AddDeviceResult, AddDeviceRequest>(request);
        }
#else
        /// <summary>
        ///  注册单个设备并返回秘钥信息
        /// </summary>
        /// <param name="request">请求参数信息</param>
        /// <returns>请求结果信息</returns>
        public async Task<AddDeviceResponse> AddDevice(AddDeviceRequest request) {
            return await new AddDeviceExecutor().Client(this).Execute<AddDeviceResponse, AddDeviceResult, AddDeviceRequest>(request).ConfigureAwait(false);
        }
#endif
#if NET40||NET35
        /// <summary>
        ///  查看产品列表接口
        /// </summary>
        /// <param name="request">请求参数信息</param>
        /// <returns>请求结果信息</returns>
        public ListProductsResponse ListProducts(ListProductsRequest request) {
            return  new ListProductsExecutor().Client(this).Execute<ListProductsResponse, ListProductsResult, ListProductsRequest>(request);
        }
#else
        /// <summary>
        ///  查看产品列表接口
        /// </summary>
        /// <param name="request">请求参数信息</param>
        /// <returns>请求结果信息</returns>
        public async Task<ListProductsResponse> ListProducts(ListProductsRequest request) {
            return await new ListProductsExecutor().Client(this).Execute<ListProductsResponse, ListProductsResult, ListProductsRequest>(request).ConfigureAwait(false);
        }
#endif
#if NET40||NET35
        /// <summary>
        ///  查询设备详情
        /// </summary>
        /// <param name="request">请求参数信息</param>
        /// <returns>请求结果信息</returns>
        public QueryDeviceDetailResponse QueryDeviceDetail(QueryDeviceDetailRequest request) {
            return  new QueryDeviceDetailExecutor().Client(this).Execute<QueryDeviceDetailResponse, QueryDeviceDetailResult, QueryDeviceDetailRequest>(request);
        }
#else
        /// <summary>
        ///  查询设备详情
        /// </summary>
        /// <param name="request">请求参数信息</param>
        /// <returns>请求结果信息</returns>
        public async Task<QueryDeviceDetailResponse> QueryDeviceDetail(QueryDeviceDetailRequest request) {
            return await new QueryDeviceDetailExecutor().Client(this).Execute<QueryDeviceDetailResponse, QueryDeviceDetailResult, QueryDeviceDetailRequest>(request).ConfigureAwait(false);
        }
#endif
#if NET40||NET35
        /// <summary>
        ///  分页查询设备信息,支持一个或多个条件
        /// </summary>
        /// <param name="request">请求参数信息</param>
        /// <returns>请求结果信息</returns>
        public QueryDevicePageResponse QueryDevicePage(QueryDevicePageRequest request) {
            return  new QueryDevicePageExecutor().Client(this).Execute<QueryDevicePageResponse, QueryDevicePageResult, QueryDevicePageRequest>(request);
        }
#else
        /// <summary>
        ///  分页查询设备信息,支持一个或多个条件
        /// </summary>
        /// <param name="request">请求参数信息</param>
        /// <returns>请求结果信息</returns>
        public async Task<QueryDevicePageResponse> QueryDevicePage(QueryDevicePageRequest request) {
            return await new QueryDevicePageExecutor().Client(this).Execute<QueryDevicePageResponse, QueryDevicePageResult, QueryDevicePageRequest>(request).ConfigureAwait(false);
        }
#endif
#if NET40||NET35
        /// <summary>
        ///  新建产品
        /// </summary>
        /// <param name="request">请求参数信息</param>
        /// <returns>请求结果信息</returns>
        public CreateProductResponse CreateProduct(CreateProductRequest request) {
            return  new CreateProductExecutor().Client(this).Execute<CreateProductResponse, CreateProductResult, CreateProductRequest>(request);
        }
#else
        /// <summary>
        ///  新建产品
        /// </summary>
        /// <param name="request">请求参数信息</param>
        /// <returns>请求结果信息</returns>
        public async Task<CreateProductResponse> CreateProduct(CreateProductRequest request) {
            return await new CreateProductExecutor().Client(this).Execute<CreateProductResponse, CreateProductResult, CreateProductRequest>(request).ConfigureAwait(false);
        }
#endif
#if NET40||NET35
        /// <summary>
        ///  修改产品
        /// </summary>
        /// <param name="request">请求参数信息</param>
        /// <returns>请求结果信息</returns>
        public UpdateProductResponse UpdateProduct(UpdateProductRequest request) {
            return  new UpdateProductExecutor().Client(this).Execute<UpdateProductResponse, UpdateProductResult, UpdateProductRequest>(request);
        }
#else
        /// <summary>
        ///  修改产品
        /// </summary>
        /// <param name="request">请求参数信息</param>
        /// <returns>请求结果信息</returns>
        public async Task<UpdateProductResponse> UpdateProduct(UpdateProductRequest request) {
            return await new UpdateProductExecutor().Client(this).Execute<UpdateProductResponse, UpdateProductResult, UpdateProductRequest>(request).ConfigureAwait(false);
        }
#endif

            /// <summary>
            ///  默认IothubClient 构造器 接口
            ///</summary>
            public interface Builder
            {

                /// <summary>
                /// 设置认证信息参数
                /// </summary>
                /// <param name="provider">认证信息提供对象</param>
                /// <returns>iothubClient 构造器</returns>
                Builder CredentialsProvider(CredentialsProvider provider);

                /// <summary>
                /// 设置请求环境参数
                /// </summary>
                /// <param name="environment">环境参数信息</param>
                /// <returns>iothubClient 构造器</returns>
                Builder Environment(Core.Client.SDKEnvironment environment);

                /// <summary>
                /// http 请求配置信息
                /// </summary>
                /// <param name="config">http 请求配置信息</param>
                /// <returns>iothubClient 构造器</returns>
                Builder HttpRequestConfig(HttpRequestConfig config);

                /// <summary>
                ///  构造IothubClient 对象
                ///</summary>
                IothubClient Build();
            }

            /// <summary>
            ///  默认IothubClient 构造器
            ///</summary>
            public class DefaultBuilder : Builder
            {
                /// <summary>
                ///  IothubClient service client
                /// </summary>
                private  IothubClient iothubClient;

                /// <summary>
                ///  默认IothubClient 构造器构造对象
                ///</summary>
                public DefaultBuilder()
                {
                    iothubClient = new IothubClient();
                }

                /// <summary>
                ///  构造IothubClient 对象
                ///</summary>
                public IothubClient Build()
                {
                    if (iothubClient.CredentialsProvider == null)
                    {
                        //if credentialsProvider not set, try load jdcloud global default  credentials provider
                        iothubClient.credentialsProvider = JdCloud.DefaultInstance.GetCredentialsProvider();
                        if (iothubClient.credentialsProvider == null)
                        {
                            throw new ArgumentNullException("IothubClient build error: jdcloud credentials provider not set");
                        }
                    }
                    if (iothubClient.HttpRequestConfig == null)
                    {
                        iothubClient.httpRequestConfig = JdCloud.DefaultInstance.GetHttpRequestConfig();
                        if (iothubClient.httpRequestConfig == null)
                        {
                        throw new ArgumentNullException("IothubClient build error: http request config not set");
                        }
                    }
                    return iothubClient;
                }

                /// <summary>
                /// 设置认证信息参数
                /// </summary>
                /// <param name="provider">认证信息提供对象</param>
                /// <returns>iothubClient 构造器</returns>
                public Builder CredentialsProvider(CredentialsProvider provider)
                {
                    iothubClient.credentialsProvider = provider;
                    return this;
                }

                /// <summary>
                /// 设置请求环境参数
                /// </summary>
                /// <param name="environment">环境参数信息</param>
                /// <returns>iothubClient 构造器</returns>
                public Builder Environment(SDKEnvironment environment)
                {
                    iothubClient.environment = environment;
                    return this;
                }

                /// <summary>
                /// http 请求配置信息
                /// </summary>
                /// <param name="config">http 请求配置信息</param>
                /// <returns>iothubClient 构造器</returns>
                public Builder HttpRequestConfig(HttpRequestConfig config)
                {
                    iothubClient.httpRequestConfig = config;
                    return this;
                }
            }
    }
}
